<?php if ($sf_user->hasFlash('saved_flash')){
?>		
			<div id="notification" class="nNote nSuccess hideit" onclick="$('#notification').hide('slow')" style="margin-top: 40px;">
                <p><strong>SUCCESS: </strong>Template Definition Saved</p>
         </div>

<?php 
}?>

<?php if ($sf_user->hasFlash('alert_flash')){
?>		
			<div id="alert_msg" class="nNote nWarning hideit" onclick="$('#alert_msg').hide('slow')" style="margin-top: 40px;">
                <p><strong>ALERT: </strong>Need to create content and footer</p>
         </div>

<?php 
}?>
	<div class="widget" id="template_div">
		<?php include_partial('template', array('form' => $form, 'directory' => $directory, 'selected_directory' => $selected_directory,'categories' => $categories,'levelIds' => $levelIds)); ?>
	</div>
	

	<div class="fix"></div>
	<form action="<?php echo url_for("listing/saveListings")?>" method="post" class="mainForm" enctype="multipart/form-data" name="upload_form" id="upload_form">
	<div class="widget" id="categories_div">
		<div class="head"><h5 class="iList">Upload File</h5></div>
		<div class="rowElem noborder">
		<div style="clear: both;">
			<div style="float: left; width: 570px">
				<label>Usual file input :</label> 
			     <div style="margin-top: 10px">
			          <input type="file" class="fileInput" id="fileInput" name="fileInput" />
			     </div>			
			</div>
			<div style="float: left;margin-top: 10px">
	           <input type="submit" value="Save" class="greyishBtn" onclick="javascript:if(!validate()){return false;}" />
			</div>
		</div>
		
    <div class="fix"></div>
	     </div>
	     
    </div>
    <input type="hidden" id="h_directory_id" name="h_directory_id" value="<?php echo $selected_directory?>"/>
    
</form>

<div id="error_msg" class="error_msg" style="clear:both; display: none; cursor:pointer;" onclick="$(this).hide('slow')">
		<div id="msg_text" ></div>
	</div>

<div class="widget" id="categories_div">
<div class="head"><h5 class="iFrames">Listings</h5></div>
            <table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>Elements</th>
                    </tr>
                </thead>
                <tbody>
                    	<?php 
                    	
                    	foreach ($lists as $list){ 
                    	?>
	                    <tr class="gradeA">
	                    		
	                        	<td><?php echo $list->getName(); ?></td>
	                        			                        	
	                        	<td>
	                        	<?php 
	                        	$list_fields = $list->getListField();
	                        	$fields_str = '';
	                        	foreach ($list_fields as $list_field) {
	                        		$fields_str .= $list_field->getName() . ', ';
	                        	}
	                        	if(strlen($fields_str) > 0){
	                        		$fields_str = substr($fields_str, 0, strlen($fields_str) - 2);
	                        	}
	                        	echo $fields_str;
	                        	?>
	                        		
		                        </td>
		                </tr>
                        <?php }?>
                </tbody>
            </table>
</div>
	
	
<script>

/*
$("form#upload_form").submit(function (event){
    event.preventDefault();
    if (!validate()){ 
        return false;
    }
    else{
    	$("form#upload_form").submit();   
    }
})
*/

function validate(){
	var valid = true;
	var error_msg = "";
	if ($("#fileInput").attr("value") == ""){
		valid = false;
		error_msg = "CSV file required";
	};	
		
	if (!valid){
		$('#msg_text').html(error_msg);
		$('#error_msg').show('fast');
	}
	return valid;			
}

	$('form').jqTransform({imgPath:'../images/forms'});

	oTable = $('#example').dataTable({
		"bJQueryUI": true,
		"sPaginationType": "full_numbers",
		"sDom": '<""f>t<"F"lp>',
		"bDestroy": true
	});

	
</script> 